<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
  <title>答疑页面</title>
  <link rel="stylesheet" href="../css/exchange.css">
</head>
<body>
<div class="site">
  当前所在位置：
  <ul>
    <c:forEach var="parentPage" items="${navigationPath}">
      <li>
        <a href="${parentPage.childUrl}/塞尔达传说:王国之泪">${parentPage.childName}</a>
      </li>
    </c:forEach>
  </ul>
</div>
<div class="container">
  <h1>答疑论坛</h1>
  <c:forEach items="${commentList}" var="item">
    <div class="question">
      <p>
        <span>${item.user.username}</span>
          ${item.comment.date}
      </p>
      <p class="answer">${item.comment.context}</p>
    </div>
  </c:forEach>

  <div class="input-container">
    <c:if test="${not empty sessionScope.user}">
      <form action="/comment/add/${sessionScope.user.id}" method="post">
        <input type="text" name="context" placeholder="输入您的回复...">
        <button>发送</button>
      </form>
    </c:if>
    <c:if test="${empty sessionScope.user}">
      <button onclick="showLoginModal()">请登录后发表评论</button>
    </c:if>
  </div>
</div>

<script>
  function showLoginModal() {
    alert("请先登录！");
    var form = document.createElement('form');
    form.method = 'GET';
    form.action = '/zelda/login'; // 提交登录请求的路径
    document.body.appendChild(form);
    form.submit();
  }
</script>

</body>
</html>